﻿using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;

/// <summary>
/// Summary description for DABasis
/// </summary>
namespace ShopLib.DA
{

    public class DABasis
    {
        protected static string strConnect;

        public DABasis()
        {
            GetConnection();
        }

        static DABasis()
        {
            strConnect = ConfigurationManager.ConnectionStrings["LocalSqlServer"].ConnectionString.ToString();
        }
        /// <summary>
        /// Data Connection Initialization Class
        /// </summary>
        /// <returns>Object of type SqlConnection</returns>
        protected SqlConnection GetConnection()
        {
            SqlConnection oConnection = new SqlConnection(strConnect);
            return oConnection;
        }

        /// <sumary>
        /// gives the list of activities of the (person)ID for the particular EntryDate
        /// </summary>
        /// <param name="nPersID">PersID attribute of ProjectInvolvement</param>
        /// <param name="dtEntry">EntryDate attribute of ProjectInvolvement</param>
        /// <returns>DataSet and the table name is "dtDayRecord" </returns> 
        public DataSet GetBasketContent(Guid OrderId, string SortBy)
        {
            SqlConnection oConnection = GetConnection();

            // build the command
            SqlCommand oCommand = new SqlCommand("Shop_Basket_GetContent", oConnection);
            oCommand.CommandType = CommandType.StoredProcedure;

            // Parameters
            SqlParameter paraOrderID = new SqlParameter("@ordersId", SqlDbType.UniqueIdentifier, 36);
            paraOrderID.Value = OrderId;
            oCommand.Parameters.Add(paraOrderID);
            SqlParameter paraSort = new SqlParameter("@colname", SqlDbType.NVarChar, 100);
            paraSort.Value = SortBy;
            oCommand.Parameters.Add(paraSort);

            // Adapter and DataSet
            SqlDataAdapter oAdapter = new SqlDataAdapter();
            oAdapter.SelectCommand = oCommand;
            DataSet oDataSet = new DataSet();
            try
            {
                oConnection.Open();
                oAdapter.Fill(oDataSet, "dtBasketContent");
                return oDataSet;
            }
            catch (Exception oException)
            {

                throw oException;
            }
            finally
            {
                oConnection.Close();
            }
        }

    }
}
